package Servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/loginServlet")
public class loginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{

	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		String username = request.getParameter("user");
		String password = request.getParameter("pwd");
		if(username==null || username=="")
			System.out.println("ERROR-> Empty Username");
		System.out.println("Login for "+username+"->"+password);
		RequestDispatcher rd = null;
		switch(username)
		{
		case "student" : rd=getServletContext().getRequestDispatcher("/View/studentDashboard.jsp");break;
		case "instructor" : rd=getServletContext().getRequestDispatcher("/View/instructorDashboard.jsp");break;
		case "admin" : rd=getServletContext().getRequestDispatcher("/View/index.jsp");break;
		default : rd=getServletContext().getRequestDispatcher("/View/login.jsp");break;
		}
		rd.forward(request, response);
	}

}
